﻿#region Using directives

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MCMLXVII.BackEnd.Services.SystemConfiguration.Messages;
using MCMLXVII.BackEnd.Services.Common.Messages;
using MCMLXVII.BackEnd.Services.OrganizationChart.Interfaces;
using MCMLXVII.BackEnd.Services.OrganizationChart.Messages;

#endregion

namespace MCMLXVII.Tools.OrganizationChart
{
    partial class frmMoveDestination : Form
    {
        private Hashtable NodeCache = new Hashtable();
        private OrganizationTreeNode  EditingNode;

        public int SourceNode;
        public bool Cancel = false;
        private int _SelectedNode;
        public int SelectedNode
        {
            get
            {
                return _SelectedNode;
            }
        }


        public frmMoveDestination()
        {
            InitializeComponent();
        }


        private void LoadOrganizationTree()
        {
            msgOrganizationNodeInfo root = BusinessActions.GetOrganizationDestinationTree(SourceNode);
            TreeNode tn = new TreeNode(root.Name, 0, 0);
            tn.Tag = root.NodeID.ToString();
            OrganizationTree.Nodes.Add(tn);
            CompleteNodes(tn, root.FirstChild);
            tn.Expand();
        }


        private void CompleteNodes(TreeNode tn, msgOrganizationNodeInfo root)
        {
            if (root != null)
            {
                TreeNode tch = new TreeNode(root.Name, 1, 2);
                tch.Tag = root.NodeID.ToString();
                tn.Nodes.Add(tch);
                CompleteNodes(tch, root.FirstChild);

                while (root.NextBrother != null)
                {
                    TreeNode tcx = new TreeNode(root.NextBrother.Name, 1, 2);
                    tcx.Tag = root.NextBrother.NodeID.ToString();
                    tn.Nodes.Add(tcx);
                    CompleteNodes(tcx, root.NextBrother.FirstChild);
                    root = root.NextBrother;
                }
            }
        }
        
        private void frmMoveDestination_Load(object sender, EventArgs e)
        {
            LoadOrganizationTree();
        }

        private void OrganizationTree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            _SelectedNode = Int32.Parse(e.Node.Tag.ToString());
            cmdMove.Enabled = true;
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void cmdMove_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

    }
}